//
//  NSBundle+SDKNibloading.m
//  SpokenEnglishSDK
//
//  Created by linziyuan on 2017/6/26.
//  Copyright © 2017年 creative. All rights reserved.
//

#import "NSBundle+SDKNibloading.h"
#import "NSObject+Telen.h"

@implementation NSBundle (SDKNibloading)

+ (void)load
{
    //[self swizzleSelector:@selector(loadNibNamed:owner:options:) withSelector:@selector(sp_sdk_loadNibNamed:owner:options:)];
    [self swizzleSelector:@selector(pathForResource:ofType:) withSelector:@selector(jrsdk_pathForResource:ofType:)];
}


- (NSString *)jrsdk_pathForResource:(NSString *)name ofType:(NSString *)ext {
    NSBundle *finalBundel = [NSBundle bundleForClass:NSClassFromString(@"JReaderSDKManager")];
    if (finalBundel) {
        NSString *sourceBundel = [finalBundel jrsdk_pathForResource:name ofType:ext];
        if (sourceBundel == nil) {
            return [self jrsdk_pathForResource:name ofType:ext];
        }
        return sourceBundel;
    }
    return [self jrsdk_pathForResource:name ofType:ext];
}


- (NSArray *)sp_sdk_loadNibNamed:(NSString *)name owner:(nullable id)owner options:(nullable NSDictionary *)options  {
    NSBundle *finalBundel = [NSBundle bundleForClass:NSClassFromString(@"JReaderSDKManager")];
    if (finalBundel) {
        NSArray* nibs = [finalBundel sp_sdk_loadNibNamed:name owner:owner options:options];
        if (nibs == nil || !nibs.count) {
            return [self sp_sdk_loadNibNamed:name owner:owner options:options];
        }
        return nibs;
    }
    return [self sp_sdk_loadNibNamed:name owner:owner options:options];
}


@end
